<?php

class aliexpress extends AbstractParser
{

	protected $_url = 'http://www.aliexpress.com/category/63705/earphones-headphones.html?g=y';

	public function getData($html)
	{
		$result = array();
		
		$html = $this->_cutSpaces( $html );

//        echo $html; exit;

		$pattern = '<div.*id="list-items".*>(.*)</ul></div>';
		$matched = $this->_match( $pattern, $html );
//        print_r($matched); exit;
		
		if(empty($matched[1][0]))
			return $result;
		
		$html = $matched[1][0];
		
		//print_r($matched); exit;
		
		$pattern = '<a class="picRind.*" href="(.*)">.*</a>';
		$matched = $this->_match( $pattern, $html );
		
		print_r($matched); exit;
		
		if(!empty($matched[1]) && !empty($matched[2]))
		{
			foreach($matched[1] as $i => $row)
			{
				$result[$i][$this->_stripTags($matched[1][$i])] = $this->_stripTags($matched[2][$i]);
			}
		}
		
		//print_r($result); exit;
		
		return $result;
		
		
	}

    public function getNextPage($html)
    {
        $result = array();

        $html = $this->_cutSpaces( $html );

//        echo $html; exit;

        $pattern = '<span class="ui-pagination-active">.*</span><a rel="nofollow" href="(.*)".*>(\d*)</a>';
        $matched = $this->_match( $pattern, $html );
//        print_r($matched); exit;

        if(empty($matched[1][0]))
            return $result;

        $result = $matched[1][0];

        return $result;
    }

    public function getList($html)
    {
        $result = array(
//            'url' => '',
//            'photo' => '',
//            'free_shipping' => '',
        );

        $html = $this->_cutSpaces( $html );

//        echo $html; exit;

        $pattern = '<div.*id="list-items".*>(.*)</ul></div>';
        $matched = $this->_match( $pattern, $html );
//        print_r($matched); exit;

        if(empty($matched[1][0]))
            return $result;

        $html = $matched[1][0];

        //print_r($matched); exit;

        $pattern = '<a class="picRind.*" href="(.*)"><img.*src="(.*)".*></a>';
        $matched = $this->_match( $pattern, $html );

//        print_r($matched); exit;

        if(empty($matched[1]))
            return $result;

        foreach($matched[1] as $i => $url)
        {
            $result[$i]['url'] = $url;

            if(isset($matched[2][$i]))
                $result[$i]['photo'] = $matched[2][$i];
        }

        return $result;
    }

    public function getItem($html)
    {}

}